# -*- encoding: utf-8 -*-

from django import forms
from django.conf import settings
from django.core.mail import EmailMessage
from django.utils.translation import ugettext_lazy as _

class ContactForm(forms.Form):
    name = forms.CharField(label=_(u'Nom '), required=False)
    mail = forms.EmailField(label=_(u'Email *'))
    subject = forms.CharField(label=_(u'Objet'), required=False)
    message = forms.CharField(label=_(u"Message *"), widget=forms.Textarea)

    def send(self, mails=[]):
        if self.is_valid():
            if not mails:
                mails = [a[1] for a in settings.ADMINS]
            subject = u'[%s] %s' % (settings.SITE_NAME, 
                                    self.cleaned_data['subject'])
            msg = EmailMessage(subject, self.cleaned_data['message'],
                               self.cleaned_data['mail'], mails)
            try:
                msg.send()
            except:
                return False

            return True

        return False
